/*
 * generate by table-builder.Don't modify it
 */
using IQIGame.Onigao.Framework.Serialization;
using IQIGame.Onigao.GamePlay;
using System.Collections.Generic;


namespace CfgTable
{
    public partial class TbCfgMonster
    {
        private readonly Dictionary<int, CfgMonster> _dataMap;
        private readonly List<CfgMonster> _dataList;


        public TbCfgMonster(ByteBuf _buf)
        {
            //first read common data
            _TbCommonMonster _commonData = null;
            var commonSize = _buf.ReadSize();
            if (commonSize > 0)
            {
                _commonData = new _TbCommonMonster(_buf);
            }

            //then read row data
            var size = _buf.ReadSize();
            _dataMap = new Dictionary<int, CfgMonster>(size * 3 / 2);
            _dataList = new List<CfgMonster>(size);

            for (int i = 0; i < size; i++)
            {
                CfgMonster _v;
                _v = CfgMonster.DeserializeCfgMonster(_buf, _commonData);
                _dataList.Add(_v);
                _dataMap.Add(_v.Id, _v);
            }

            // read extra fields 

            PostInit();
        }

        public IReadOnlyDictionary<int, CfgMonster> DataMap => _dataMap;
        public IReadOnlyList<CfgMonster> DataList => _dataList;

        public CfgMonster Get(int key)
        {
            if (_dataMap.TryGetValue(key, out var v))
            {
                return v;
            }
            IQIGame.Onigao.Framework.LogGame.LogError("[TbCfgMonster] config not found,id:" + key.ToString());

            return null;
        }

        public CfgMonster GetWithoutError(int key) => _dataMap.TryGetValue(key, out var v) ? v : null;

        /// <summary>
        /// table data file
        /// </summary>
        public static string TableFileName { get; } = "monster";

        /// <summary>
        /// load table function
        /// </summary>
        public static TbCfgMonster LoadFromFunc(System.Func<string, ByteBuf> loadFunc)
        {
            return new TbCfgMonster(loadFunc(TableFileName));
        }

        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();

    }

    public partial class CfgMonster
    {
        private CfgMonster(ByteBuf _buf, _TbCommonMonster _commonData)
        {
            Id = _buf.ReadInt();
            Name = TableCenter.GetI18NText(_buf.ReadInt());
            EntityType = _buf.ReadInt();
            { int dataIndex = _buf.ReadInt() - 1; EntityAsset = _commonData._field0[dataIndex]; }
            Radius = _buf.ReadInt();
            { int dataIndex = _buf.ReadInt() - 1; BattleHeadIcon = _commonData._field1[dataIndex]; }
            IsBoss = _buf.ReadBool();
            IsWarning = _buf.ReadBool();
            { int dataIndex = _buf.ReadInt() - 1; Skill = _commonData._field2[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; WeakType = _commonData._field3[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; AI = _commonData._field4[dataIndex]; }
            Diglog = TableCenter.GetI18NText(_buf.ReadInt());
            { int dataIndex = _buf.ReadInt() - 1; SideAngle = _commonData._field5[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; BackAngle = _commonData._field6[dataIndex]; }

            PostInit();
        }

        internal static CfgMonster DeserializeCfgMonster(ByteBuf _buf, _TbCommonMonster _commonData)
        {
            return new CfgMonster(_buf, _commonData);
        }

        /// <summary>
        /// major key
        /// </summary>
        public int Id { get; private set; }

        /// <summary>
        /// 名称文本
        /// </summary>
        public string Name { get; private set; }
        /// <summary>
        /// 元素类型（0:主角|1:关卡模型）
        /// </summary>
        public int EntityType { get; private set; }
        /// <summary>
        /// 实体资源名
        /// </summary>
        public string EntityAsset { get; private set; }
        /// <summary>
        /// 实体半径(cm)
        /// </summary>
        public int Radius { get; private set; }
        /// <summary>
        /// 图标(Assets\Res\05_Images\Sprite\Icon_BattleHead)
        /// </summary>
        public string BattleHeadIcon { get; private set; }
        /// <summary>
        /// 是否是bOSS
        /// </summary>
        public bool IsBoss { get; private set; }
        /// <summary>
        /// 是否大招预警
        /// </summary>
        public bool IsWarning { get; private set; }
        /// <summary>
        /// 技能
        /// </summary>
        public IReadOnlyList<int> Skill { get; private set; }
        /// <summary>
        /// 弱点类型（1物理，2魔法,3冰，4火，5雷，）
        /// </summary>
        public IReadOnlyList<int> WeakType { get; private set; }
        /// <summary>
        /// AI配置
        /// </summary>
        public string AI { get; private set; }
        /// <summary>
        /// 大招战斗内冒字
        /// </summary>
        public string Diglog { get; private set; }
        /// <summary>
        /// 侧面角度
        /// </summary>
        public IReadOnlyList<int> SideAngle { get; private set; }
        /// <summary>
        /// 背面角度
        /// </summary>
        public IReadOnlyList<int> BackAngle { get; private set; }

        /// <summary>
        /// BattleHeadIcon 资源全路径
        /// </summary>
        public string BattleHeadIcon_fullPath => $"Res/05_Images/Sprite/Icon_BattleHead/{BattleHeadIcon}";
        /// <summary>
        /// EntityAsset 资源全路径
        /// </summary>
        public string EntityAsset_fullPath => $"Res/03_Prefabs/Entity/{EntityAsset}/mb_{EntityAsset}.prefab";

        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();
    }

    /// <summary>
    /// internal common data.Optimize memory
    /// </summary>
    internal class _TbCommonMonster
    {

        internal IReadOnlyList<string> _field0 { get; private set; }
        internal IReadOnlyList<string> _field1 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<int>> _field2 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<int>> _field3 { get; private set; }
        internal IReadOnlyList<string> _field4 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<int>> _field5 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<int>> _field6 { get; private set; }
        internal _TbCommonMonster(ByteBuf _buf)
        {
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field0 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field1 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][]; _field2 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][]; _field3 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field4 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][]; _field5 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][]; _field6 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
        }

    }
}
